//
//  EGShopCartManager.m
//  Orchard
//
//  Created by ios001 on 16/8/23.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "EGShopCartManager.h"
#import "EGShopCartModel.h"


@interface EGShopCartManager()

@property(nonatomic,strong)NSMutableArray<EGShopCartModel *>* goodsList;

@end

@implementation EGShopCartManager

IMPLEMENTATION_SINGLETON(EGShopCartManager)

-(void)addGoods:(EGShopCartModel *)goods{
    for (int i = 0 ; i < self.goodsList.count; i++) {
        EGShopCartModel *model  = self.goodsList[i];
        //如果商品列表中有这个品种,此商品数量+1
        if ([model.identifier isEqualToString:goods.identifier]) {
            
            self.goodsList[i].goodsNums++;
            
        }else{
            //如果商品列表中没有这个品种,直接添加品种
            [self.goodsList removeObject:self.goodsList[i]];
        }
    }
    self.totalGoods++;
}





-(void)ReduceGoods:(EGShopCartModel *)goods{
    for (int i = 0 ; i < self.goodsList.count; i++) {
        EGShopCartModel* model  = self.goodsList[i];
        //判断商品标识,如果相同删除,防止相同的商品被多次删除
        if ([model.identifier isEqualToString:goods.identifier]) {
            self.goodsList[i].goodsNums--;
        }
    }
    self.totalGoods--;
}

-(void)getGoodsList:(EGShopCartModel *)manager withList:(NSMutableArray<EGShopCartModel *>*)goodsList{
}



//MARK:懒加载
-(NSMutableArray<EGShopCartModel *> *)goodsList{
    if (_goodsList == nil) {
        _goodsList = [NSMutableArray array];
    }
    return _goodsList;
}



@end
